<template>
  <div class="house-card">
    <div class="house-card-img">
      <van-tag
        type="warning"
        class="house-card-type-tag"
      >
        {{info.type}}
      </van-tag>
      <img
        :src="info.pic"
        style="height: 100%; width: 100%;"
      />
    </div>
    <div class="house-card-content">
      <div class="house-card-title">
        {{ info.name }}
        <span>
          {{ info.area }}㎡
        </span>
        <div
          class="house-card-apply-button"
          @click="onClickLeft"
        >
          申请住房
        </div>
      </div>
      <div class="house-card-description">
        {{ `集团:${info.gro} 站段:${info.station} 车间:${info.shop}` }}
        {{ info.location }}
        {{ `床位:${info.maxbed} 入住人数:${info.hasbed}`}}
      </div>
      <span class="house-card-price">¥{{ info.price }}</span>
    </div>
    <van-dialog v-model="show" title="申请住房" show-cancel-button @confirm="submit">
      <div style="text-align: center">确认申请 {{ info.name }} 吗？</div>
      <van-field
        type="textarea"
        v-model="applyContent"
        placeholder="申请理由"
      />
      <p class="sign-info">
        {{ signInfo }}
      </p>
    </van-dialog>
  </div>
</template>

<script>
import housePhoto from "@/assets/house.png"
export default {
  name: 'HouseCard',
  props: {
    info: {
      type: Object,
      default: {},
    },
    title: {
      type: String,
      default: '',
    },
    desc: {
      type: String,
      default: '',
    },
    photoUrl: {
      type: String,
      default: housePhoto,
    },
  },
  data() {
    return {
      show: false,
      applyContent: '',
      signInfo: '',
    };
  },
  methods: {
    onClickLeft() {
      this.HttpManager.getSignInfo({
        uid: sessionStorage.getItem("userid"),
        bid: this.info.bid,
      }).then(res => {
        this.signInfo = res;
        this.show = true;
      })
    },
    submit() {
      this.HttpManager.applyBuilding({
        uid: sessionStorage.getItem("userid"),
        bid: this.info.bid,
        reason: this.applyContent,
      }).then(res => {
        if (res.code === 0) {
          this.$notify({ type: "success", message: '申请成功，等待审核' });
        } else {
          this.$notify({ type: "danger", message: res.msg });
          this.$router.push('mine');
        }
      })
    },
  }
}
</script>

<style lang="less" scoped>
  .house-card {
    border-radius: 4px;
    background-color: #fafafa;
    display: flex;
    box-sizing: border-box;
    height: 106px;
    padding: 4px;
    position: relative;

    &:not(:first-child) {
      margin-top: 8px;
    }

    &-type-tag {
      position: absolute;
      top: 0;
      left: 0;
    }

    &-img {
      position: relative;
      width: 30%;
      margin-right: 5px;
    }

    &-content {
      flex: 1;
      display: flex;
      flex-direction: column;
    }

    &-title {
      max-height: 32px;
      font-weight: 500;
      display: flex;
      justify-content: space-between;
    }

    &-description {
      max-height: 60px;
      font-size: 12px;
      white-space: pre-line;
      text-overflow: ellipsis;
    }

    &-price {
      position: absolute;
      bottom: 15px;
      right: 10px;
    }

    &-apply-button {
      font-size: 14px;
      border-radius: 8px;
      padding: 3px 6px;
      background-color: #ffa850;
      cursor: pointer;
    }

    .sign-info {
      white-space: pre-line;
      font-size: 14px;
      padding: 0 10px;
    }
  }
</style>
